package cn.genmer.test.security.utils;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class RandomAddressGenerator {

    // 定义省、市和区的数组
    private static final String[] PROVINCES = {
            "北京市", "上海市", "广东省", "江苏省", "浙江省", "四川省", "山东省",
            "湖北省", "湖南省", "陕西省", "福建省", "海南省", "黑龙江省",
            "吉林省", "辽宁省", "河北省", "河南省", "安徽省", "广西壮族自治区",
            "内蒙古自治区", "新疆维吾尔自治区", "西藏自治区", "宁夏回族自治区", "澳门特别行政区",
            "香港特别行政区", "天津市", "重庆市"
    };

    private static final String[][] CITIES = {
            {"北京市"},
            {"上海市"},
            {"广州市", "深圳市", "珠海市"},
            {"南京市", "苏州市", "无锡市"},
            {"杭州市", "宁波市", "温州市"},
            {"成都市", "绵阳市", "德阳市"},
            {"济南市", "青岛市", "烟台市"},
            {"武汉市", "黄石市", "襄阳市"},
            {"长沙市", "株洲市", "湘潭市"},
            {"西安市", "宝鸡市", "咸阳市"},
            {"福州市", "厦门市", "宁德市"},
            {"海口市"},
            {"哈尔滨市", "齐齐哈尔市"},
            {"长春市", "吉林市"},
            {"沈阳市", "大连市"},
            {"石家庄市", "保定市"},
            {"郑州市", "开封市"},
            {"合肥市", "芜湖市"},
            {"南宁", "桂林市", "柳州市"},
            {"呼和浩特市", "包头市"},
            {"乌鲁木齐市", "克拉玛依市"},
            {"拉萨市"},
            {"银川市"},
            {"香港特别行政区"},
            {"澳门特别行政区"},
            {"天津市"},
            {"重庆市"}
    };

    private static final String[][] DISTRICTS = {
            {"东城区", "西城区", "朝阳区"},
            {"黄浦区", "徐汇区", "浦东新区"},
            {"天河区", "越秀区", "海珠区"},
            {"鼓楼区", "秦淮区", "建邺区"},
            {"上城区", "下城区", "江干区"},
            {"锦江区", "青羊区", "成华区"},
            {"历下区", "市中区", "天桥区"},
            {"江汉区", "武昌区", "洪山区"},
            {"芙蓉区", "天心区", "岳麓区"},
            {"新城区", "碑林区", "莲湖区"},
            {"鼓楼区", "仓山区", "台江区"},
            {"美兰区"},
            {"道里区", "南岗区", "平房区"},
            {"朝阳区", "二道区", "南关区"},
            {"和平区", "大连湾", "沙河口区"},
            {"桥西区", "长安区", "裕华区"},
            {"金水区", "二七区", "管城回族区"},
            {"蜀山区", "庐阳区", "瑶海区"},
            {"青秀区", "兴宁区", "良庆区"},
            {"新城区", "赛罕区", "回民区"},
            {"天山区", "沙依巴克区"},
            {"城关区"},
            {"兴庆区"},
            {"中西区", "湾仔区", "九龙区"},
            {"花地玛堂区"},
            {"和平区", "南开区", "河东区"},
            {"渝中区", "江北区", "南岸区"}
    };

    public static List<String> generateRandomAddresses(int count) {
        Random random = new Random();
        List<String> addresses = new ArrayList<>();

        for (int i = 0; i < count; i++) {
            // 随机选择省
            String province = PROVINCES[random.nextInt(PROVINCES.length)];

            // 根据省随机选择市
            int provinceIndex = getProvinceIndex(province);
            String city = CITIES[provinceIndex][random.nextInt(CITIES[provinceIndex].length)];

            // 根据市随机选择区
            int cityIndex = getCityIndex(provinceIndex, city);
            String district = DISTRICTS[cityIndex][random.nextInt(DISTRICTS[cityIndex].length)];

            // 随机生成门牌号
            int number = random.nextInt(10000);

            // 组合地址
            addresses.add(province + city + district + number + "号");
        }

        return addresses;
    }

    private static int getProvinceIndex(String province) {
        for (int i = 0; i < PROVINCES.length; i++) {
            if (PROVINCES[i].equals(province)) {
                return i;
            }
        }
        return -1; // 未找到
    }

    private static int getCityIndex(int provinceIndex, String city) {
        for (int i = 0; i < CITIES[provinceIndex].length; i++) {
            if (CITIES[provinceIndex][i].equals(city)) {
                return provinceIndex;
            }
        }
        return -1; // 未找到
    }

    public static void main(String[] args) {
        List<String> randomAddresses = generateRandomAddresses(10000);
        // 打印结果或进一步处理
        for (String address : randomAddresses) {
            System.out.println(address);
        }
    }
}